<template>
    <div class="modal fade" id="recommenderChangeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">
					<div class="modal-header">
						<h4 class="modal-title" id="myModalLabel">变更推荐人</h4>
					</div>
					<div class="modal-body">
						<div class="form-horizontal clearfix">
							<div class="form-group  col-sm-4" style="line-height: 40px; text-align: center;" v-if="customerPremisesId">
								<font color="#f97242">请选择报备推荐人</font>
							</div>
							<div class="form-group col-sm-4" style="position:relative">
								<select class="form-control" v-model="recommenderUuid">
									<option v-for="recommender in recommenderList" :value="recommender.recommenderUuid" :key="recommender.recommenderUuid">{{ recommender.userName }}</option>
								</select>
							</div>
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn checkedBtn" v-show="btnShow" @click="changeCPRecommender">确定</button>
						<button type="button" class="btn checkedBtn" v-show="btnShow" @click="closeModal">关闭</button>
					</div>
        </div>
      </div>
    </div>
</template>

<style>
.property-consultant {
  color: #f87242;
}
.property-consultant:hover,
.property-consultant:focus {
  color: #ed3f14;
}
.view-list-close {
  cursor: pointer;
  font-weight: bold;
  position: absolute;
  right: 10px;
  top: 4px;
  font-size: 20px;
}
</style>

<script>
import { API, Log, Utils, Service } from "../../../js/base";
import CommonSelect from "../../common/CommonSelect.vue";
export default {
  //接收父组件的绑定值
  props: {
    customerPremisesId: {
      type: Number,
      default: "", //range/time
    },
    oldRecommender: {
      type: String,
      default: "",
    },
  },
  components: {
    CommonSelect,
  },
  data() {
    return {
      btnShow: true,
      customerPremisesId: "",
      oldRecommender: "",
      recommenderList: [],
      recommenderUuid: "",
    };
  },
  watch: {
    customerPremisesId(val) {
      this.customerPremisesId = val;
    },
    oldRecommender(val) {
      this.oldRecommender = val;
    },
  },
  methods: {
    getRecommenderList(obj) {
      var _this = this;
      Service.Recommend.getRecommendList(obj, _this).then((list) => {
        _this.recommenderList = list;
      });
    },
    changeCPRecommender() {
      var _this = this;
      let customerPremisesId = _this.customerPremisesId;
      let recommenderUuid = _this.recommenderUuid;
      let oldRecommender = _this.oldRecommender;
      if (!recommenderUuid) {
        layer.msg("请选择推荐人", {
          time: 2000,
        });
        return;
      }
      if (oldRecommender === recommenderUuid) {
        layer.msg("推荐人相同,无需变更", {
          time: 2000,
        });
        return;
      }
      Service.Recommend.changeCPRecommender({
        customerPremisesId,
        recommenderUuid,
        _this,
      })
        .then((rsp) => {
          if (rsp.result === "1") {
            _this.closeModal();
          }
          return rsp;
        })
        .catch((e) => {
          return e;
        });
    },
    closeModal() {
      this.recommenderUuid = "";
      this.$emit("saveRecommenderChangeReturn");
      $("#recommenderChangeModal").modal("hide");
    },
  },
};
</script>